﻿using System;
using System.Collections.Generic;
using System.Text;
using MCromwell.StaffIntranet.Task.Tasks;
using MCromwell.StaffIntranet.Core;
using MCromwell.StaffIntranet.DTO;
using MCromwell.StaffIntranet.DependencyInjection;

namespace MCromwell.StaffIntranet.Presenters
{
    public class CommonPresenter
    {
        private ICommonView view;
        private ICommonTask task;

        public CommonPresenter(ICommonView view, ICommonTask task)
        {
            if (view == null)
                throw new ArgumentNullException("view", "view cannot be null");


            if (task == null)
                throw new ArgumentNullException("task", "task cannot be null");

            this.view = view;
            this.task = task;
        }

        public CommonPresenter(ICommonView view)
            : this(view, IoC.Resolve<ICommonTask>())
        {
        }

        public void Initialize(Guid SessionId)
        {
            if (SessionIsEmpty(ref SessionId))
            {
                view.CurrentAdministrator = null;
                return;
            }
            else
            {
                AdministratorDTO foundAdministrator = task.RetrieveAdministratorFor(SessionId);
                view.CurrentAdministrator = foundAdministrator;
            }
            
        }

        private static bool SessionIsEmpty(ref Guid SessionId)
        {
            return SessionId.Equals(Guid.Empty);
        }
    }
        
}
